package com.yiwei.hdb.adapter;

import android.content.Context;
import android.text.Spanned;
import android.view.View;
import android.widget.ImageView;

import com.yiwei.hdb.R;
import com.yiwei.hdb.adapter.base.BaseRViewSubAdapter;
import com.yiwei.hdb.adapter.base.BaseViewHolder;
import com.yiwei.hdb.interfaces.OnRecyclerViewListener;
import com.yiwei.hdb.model.LoanRecordModel;
import com.yiwei.hdb.util.Spans;

import java.util.List;


/**
 * 借款记录
 * Created by MasterDong on 16/4/12.
 */

public class LoanRecordAdapterNew extends BaseRViewSubAdapter<LoanRecordModel.Data> {


    private OnRecyclerViewListener onRecyclerViewListener;
    private final int px34;
    private final int px26;

    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
        this.onRecyclerViewListener = onRecyclerViewListener;
    }


    private List<LoanRecordModel.Data> list;

    public LoanRecordAdapterNew(Context context, List<LoanRecordModel.Data> list) {
        super(context, R.layout.loan_record_items, list);
        this.list = list;
        px34 = context.getResources().getDimensionPixelSize(R.dimen.x34);
        px26 = context.getResources().getDimensionPixelSize(R.dimen.x26);
    }


    @Override
    protected void convert(BaseViewHolder viewHoder, LoanRecordModel.Data item, final int position) {
        LoanRecordModel.Data mode = item;
        viewHoder.getTextView(R.id.date).setText(mode.getDate());

        Spanned yudiString = Spans.with(context).font("￥", px26, 0xff111111).
                font(mode.getMoney() + "", px34, 0xff111111).
                build();
        viewHoder.getTextView(R.id.money).setText(yudiString);
//        viewHoder.getTextView(R.id.money).setText(mode.getMoney()+"");
//        ImageView pic = viewHoder.getImageView(R.id.pic);
//        pic.setVisibility(View.INVISIBLE);
//        if (mode.getStatus_num() != 2)
//            pic.setVisibility(View.VISIBLE);
        viewHoder.getTextView(R.id.status).setText(mode.getStatus());
        viewHoder.getTextView(R.id.deadline).setText(mode.getType_name());


        View rootView = viewHoder.getView(R.id.loan_record_item);
        rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != onRecyclerViewListener) {
                    onRecyclerViewListener.onItemClick(list, position);
                }
            }
        });
        rootView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (null != onRecyclerViewListener) {
                    return onRecyclerViewListener.onItemLongClick(list, position);
                }
                return false;
            }
        });
    }


}

